package tree;

public class PathSum112 {
    public boolean hasPathSum(TreeNode root, int targetSum) {
        if (root == null) {
            return false;
        }
        return hasPathSumRecursively(root, targetSum);
    }
    public boolean hasPathSumRecursively(TreeNode root, int targetSum) {
        if (root == null) {
            return targetSum == 0;
        }
        return hasPathSumRecursively(root.right, targetSum - root.val) ||
                hasPathSumRecursively(root.left, targetSum - root.val);
    }
}
